/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.dozor;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 *
 * @author amalikov
 */
public class Telemetry2 implements MessagePayload {
	public int failures;
	public short servoVoltage;
	public short servoCurrent;
	public byte fuel;

	@Override
	public byte[] get() {
		ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
		bb.putInt(failures);
		bb.putShort(servoVoltage);
		bb.putShort(servoCurrent);
		bb.put(fuel);
		return Arrays.copyOf(bb.array(), bb.position());
	}

	@Override
	public void set(byte[] data) {
		ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
		failures = bb.getInt();
		servoVoltage = bb.getShort();
		servoCurrent = bb.getShort();
		fuel = bb.get();
	}
	
}
